<?php
/**
 * 
 * @author HoanNT
 *
 */
class CKEditor extends CWidget {
	
    public $selector = 'textarea';
    public $options  = null;
    public $config   = null;
	
    
    /**
     * (non-PHPdoc)
     * @see CWidget::init()
     */
	public function init() {
		if(session_id() == '') {
			session_start();
		}
		$config = include(dirname(__FILE__) . '/config.php');
		$this->config = $config;
		$_SESSION['ckfinderBaseUrl'] = $config['ckfinderBaseUrl'];
	}
	
	public function run() {
		Yii::app()->clientScript->registerCoreScript('jquery');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/editor/ckeditor/ckeditor.js');
		Yii::app()->clientScript->registerScript('ckeditor_init', 'CKEDITOR.replace("' . $this->selector . '", '. CJavaScript::encode($this->config) .'); ', CClientScript::POS_READY);
	}
}